var CONFIG = require('../../../../common/config');
var CODE = require('../../../../common/code');
var OSSMgr = require('../../../../common/util/OSSMgr');
var luaUtil = require('../api4back/util/luaUtil');
var retUtil = require('./retUtil');
var rpcFunc = require('../../../routes/rpcSrv/rpcFunc.js');
var staticizeUtil = require('./staticizeUtil');
var javaSearchProjectUtil = require('./javaSearchProjectUtil');
var activityUtil = require('./activityUtil');
var YjxShowTypeModel = require('../../../../common/yjxMysql/mapping/YjxShowTypeModel');
var YjxShowTypeRModel = require('../../../../common/yjxMysql/mapping/YjxShowTypeRModel');
var YjxSearchTagModel = require('../../../../common/yjxMysql/mapping/YjxSearchTagModel');
var YjxNotificationModel = require('../../../../common/yjxMysql/mapping/YjxNotificationModel');
var YjxFeedBackModel = require('../../../../common/yjxMysql/mapping/YjxFeedBackModel');
var YjxProductVerModel = require('../../../../common/yjxMysql/mapping/YjxProductVerModel');
var YjxTmplSetModel = require('../../../../common/yjxMysql/mapping/YjxTmplSetModel');
var YjxVideoUserDocModel = require('../../../../common/yjxMysql/mapping/YjxVideoUserDocModel');
var YjxUniItemsModel = require('../../../../common/yjxMysql/mapping/YjxUniItemsModel');
var YjxCustAnimationModel = require('../../../../common/yjxMysql/mapping/YjxCustAnimationModel');
// 分词模块
var Segment = require('node-segment').Segment;// 载入分词模块
var POSTAG = require('node-segment').POSTAG;// 载入词性接口
var segment = new Segment();// 创建实例
segment.useDefault();// 使用默认的识别模块及字典，载入字典文件需要1秒，仅初始化时执行一次即可

var superagent = require('superagent');
var async = require('async');

var sundryUtil = (function () {

    function sundryUtil() {

    }



    /**
     * 获取搜索热词
     *
     * @author 严旭东
     * @date 2017-11-15
     *
     * @param callback 回调
     *          error: 错误
     *          data: 数据 参见接口: http://114.55.172.253:7000/mock/11/yjx/v1/sundry/getHotSearch_v1_0
     *
     * */
    sundryUtil.getHotSearch_v1_0 = function(callback){
        (new YjxSearchTagModel()).getHotSearch_v1_0(function(err,list){
            if(err){
                return callback(err,null)
            }
            list = list || [];
            var ret = [];
            for(var i = 0;i<list.length;i++){
                ret.push(list[i].name)
            }
            return callback(null,ret);
        })
    };


    /**
     * 获取 APP 1.0 版本的基础信息(分类,字体,颜色)
     *
     * @author 王俊
     * @date 2017-11-15
     *
     * @param device 设置标识
     * @param callback 回调
     *          error: 错误
     *          data: 数据 参见接口: http://114.55.172.253:7000/project/11/interface/api/11
     *
     * */
    sundryUtil.getAppBaseInfo_v1_0 = function (device, callback) {

        async.series([
            function (callback) {
                var ver = '1.0';
                sundryUtil.getAppShowTypesInfo(ver, function (err, data) {return callback(err,data);});
            },
            function (callback) {
                sundryUtil.getAppFineTuneFontList_v1_0(function (error, fontlist) {return callback(error, fontlist);});
            },
            function (callback) {
                sundryUtil.getAppFineTuneColorList(function (error, colorList) {return callback(error, colorList);});
            },
            function (callback) {
                sundryUtil.getAppFineTuneTextConfig(function (error, config) {return callback(error, config);});
            },
            function (callback) {
                sundryUtil.getAppControlInfo(device, function (error, config) {return callback(error, config);});
            },
            function (callback) {
                sundryUtil.getAppLenControlInfo(function (error, config) {return callback(error, config);});
            }
        ], function (error, results) {
            if (error) {
                return callback(error, null);
            }

            var data = {
                types : results[0],
                fontList : results[1],
                colorList : results[2],
                textConfig : results[3],
                appControl : results[4],
                lengthControl : results[5]
            };
            return callback(null,data);
        });

    };

    /**
     * 获取 APP 版本分类信息
     *
     * @author 王俊
     * @date   2017-11-15
     *
     * @param ver APP 版本号
     * @param callback 回调
     *          err: 失败原因
     *          types: 显示分类数组
     * */
    sundryUtil.getAppShowTypesInfo = function (ver, callback) {

        // 1. 查询对应的中上层分类
        (new YjxShowTypeModel).getAppShowTypeInfo(ver, function (getTypeErr, types) {
            if (getTypeErr || !types || types.length === 0) {
                getTypeErr = getTypeErr ? getTypeErr : '暂无分类信息';
                return callback(getTypeErr, null);
            }
            // 将 types 数组转换为字典, 便于取数据
            var typeDic = {};
            for (var i=0;i<types.length;i++) {
                var tp = types[i];
                if (!typeDic[tp.st_id]) {
                    typeDic[tp.st_id] = {
                        st_id :tp.st_id,
                        parent : tp.parent,
                        name : tp.show_type_title,
                        desc : tp.show_type_desc,
                        children:[]
                    }
                }
                // 如果有组 id, 则为最小分类, 加入到指定分类的 children 中
                if (tp.set_id) {
                    var type = typeDic[tp.st_id];
                    type.children.push({
                        setIds : [tp.set_id],
                        name : tp.set_title,
                        desc : tp.set_desc,
                        children : [],
                        column : tp.column || 2     // 数据库暂时没有设置模板组显示列数的, 此处默认给2
                    });
                }

            }
            // 组织是数据结构
            var result = [];
            for (var key in typeDic) {
                var tp = typeDic[key];
                if(tp.parent) {
                    var type = typeDic[tp.st_id];
                    var parent = typeDic[tp.parent];
                    parent.children.push(type);
                } else {
                    result.push(tp);
                }
                tp.id = tp.st_id;
                tp.set_id = undefined;
                tp.parent = undefined;
            }

            // 手动添加全部分类, 暂时至支持一层
            for (var i=0; i< result.length; i++) {
                var type = result[i];

                // 如有下辖分类, 则存在全部分类, 默认加在第一位
                if (type.children && type.children.length >0) {
                    var allType = {
                        setIds : [],
                        name : '全部',
                        desc : '全部',
                        children : [],
                        column : 2 // 手动添加的全部分类, 此处默认给2
                    };
                    // 遍历子分类, 搜集 setIds
                    for (var j=0;j<type.children.length;j++) {
                        var subType = type.children[j];
                        if (subType.setIds) {
                            allType.setIds = allType.setIds.concat(subType.setIds);
                        }
                    }
                    if (allType.setIds.length) {
                        type.children.unshift(allType);
                    }
                }
            }
            return callback(null,result);
        })
    };

    /**
     * 获取 APP 微调可使用字体列表
     *
     * @author 王俊
     * @date   2017-11-15
     *
     * @param callback 回调
     *          err: 失败原因
     *          fontList: 显示分类数组
     *
     * 数据库暂时无记录表, 暂时代码写死
     * */
    sundryUtil.getAppFineTuneFontList_v1_0 = function (callback) {
        // 默认微调用字体
        var DEFAULT_FINETUNE_FONTS = [
            {
                font:'安卓中文',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170908807_kKzqKJ9fgDXu8gVmrotN',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170903803_a6tzmeIjkNctRdch2tJ7'
            },
            {
                font:'方正仿宋简体',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170908906_6OptXbA2HU6E26Gn0IXB',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170904101_e73FrCjLUIm8o7gr4x4x'
            },
            {
                font:'刻石錄明體',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170907932_dOMa5DTeM8NrcH1w4udU',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170904485_cMzxJSaTawESnoVwlqYi'
            },
            {
                font:'方正黑体简体',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/17090921_8yfHHtBgSghHxmkmbpU2',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170904182_TybJCecTz51EzC9Tib3v'
            },
            {
                font:'方正楷体',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170908562_R3MM2j8eBmRGtHg7Z8PG',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170904330_WnBRz0TkdrDcE3vuziBJ'
            },
            {
                font:'方正书宋简体',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/17090835_Q0zrjeLgd1YR5KenLGXz',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170904423_jRDdJnwtKi3g9DwugtAU'
            },
            {
                font:'全字库正宋体',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170907855_sPbPeA1PyHoR4e09u3ed',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170904613_3BqhMwtGcPVsWN2oQ63Q'
            },
            {
                font:'台湾全字库正楷体',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170907692_9KyhMKRXgBDFRlNfpJor',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170904685_hUYc42beUNjql10jKZGo'
            },
            {
                font:'文泉驿等宽正黑',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170907576_mddOoiN5RlIJozvRJEAu',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170904841_FQFOOJyZvdsFnzU1GuU2'
            },
            {
                font:'文泉驿微米黑',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170907435_9h7B0uJoh0YMwAnoTFPr',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170905533_UQKUNepr3XuPIpmEcdWK'
            },
            {
                font:'文泉驿正黑',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170907338_HzQBh7KgjAtmGluh60as',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170905698_5C0dZhVUM8DMsuxSE9cr'
            },
            {
                font:'新蒂小丸子体小学生版',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170907230_RuJ72dltPQ3SeyOPCLIv',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170905801_GZO1YYkEaNxpWA4dDrPK'
            },
            {
                font:'站酷高端黑体',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/17090786_HxjwnZ0DdQICKBrks3pP',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170905950_nbMMsyW38x1mXQYSidfL'
            },
            {
                font:'站酷酷黑体',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170906818_Eaid4adJS8eTYKXMRw67',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/17090646_G5vqWxfnBIGdeog64NvO'
            },
            {
                font:'站酷快乐体',
                thumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170906949_YLzvhfMCNWWn8Jh1MpVU',
                hThumb:'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13396/2017/12/13/170906597_vfiyzT0fplefWfCeWRhS'
            }
        ];
        return callback(null, DEFAULT_FINETUNE_FONTS);
    };
    /**
     * 获取 APP 微调可使用颜色列表
     *
     * @author 王俊
     * @date   2017-11-15
     *
     * @param callback 回调
     *          err: 失败原因
     *          colorList: 显示分类数组
     *
     * 数据库暂时无记录表, 暂时代码写死
     * */
    sundryUtil.getAppFineTuneColorList = function (callback) {
        var DEFAULT_FINE_TUNE_COLORS = [
            [255,255,255], [254,228,227], [252,204,156], [204,254,203], [203,152,253], [102,204,254],
            [192,192,192], [213,101,100], [254,203,0],   [100,255,99],  [152,51,253],  [49,152,253],
            [128,128,128], [152,51,0],    [254,153,0],   [151,204,0],   [101,0,202],   [0,0,253],
            [0,0,0],       [128,0,0],     [254,103,0],   [0,128,0],     [50,0,100],    [0,0,127]
        ];
        return callback(null, DEFAULT_FINE_TUNE_COLORS);
    };

    /**
     * 获取 APP 微调库的文字配置信息
     *
     * @author 王俊
     * @date 2017-11-15
     *
     * @param callback  回调
     * @return {*}  配置信息
     */
    sundryUtil.getAppFineTuneTextConfig = function (callback) {
        var obj = {
            minFs : 10,
            maxFs : 300,
            minLs : -10,
            maxLs : 20,
            minCs : -10,
            maxCs : 20,
            defaultText : "{\"color\":{\"b\":34,\"ct\":202,\"g\":29,\"r\":182},\"fz\":3200,\"pc\":{\"paras\":[{\"chars\":[{\"bx\":0.00,\"by\":0.00,\"h\":112305.00,\"paths\":[{\"h\":0,\"points\":[[96638.00,-66375.00,8.00],[91013.00,-74138.00,2.00],[83588.00,-80888.00,2.00],[91576.00,-86963.00,1.00],[99676.00,-79538.00,2.00],[105863.00,-70988.00,2.00],[96638.00,-66375.00,1.00]],\"w\":0},{\"h\":0,\"points\":[[47701.00,10013.00,8.00],[61538.00,-338.00,2.00],[67557.00,-16200.00,2.00],[73576.00,-32063.00,2.00],[73463.00,-55238.00,2.00],[65701.00,-55575.00,2.00],[58951.00,-54338.00,2.00],[59401.00,-59400.00,2.00],[58951.00,-64350.00,2.00],[65701.00,-63225.00,2.00],[73463.00,-63450.00,2.00],[73463.00,-83925.00,1.00],[73463.00,-89100.00,2.00],[72563.00,-94050.00,2.00],[78413.00,-93488.00,2.00],[84263.00,-94050.00,2.00],[83363.00,-89100.00,2.00],[83363.00,-83925.00,2.00],[83363.00,-63450.00,1.00],[97538.00,-63113.00,2.00],[110701.00,-64350.00,2.00],[110251.00,-59400.00,2.00],[110701.00,-54338.00,2.00],[98776.00,-55463.00,2.00],[85838.00,-55238.00,2.00],[86063.00,-17775.00,2.00],[115313.00,10350.00,2.00],[108563.00,11138.00,2.00],[103838.00,16088.00,2.00],[86738.00,-1238.00,2.00],[80663.00,-27000.00,2.00],[74926.00,338.00,2.00],[56138.00,18225.00,2.00],[52651.00,13388.00,2.00],[47701.00,10013.00,2.00]],\"w\":0},{\"h\":0,\"points\":[[51638.00,10238.00,8.00],[47026.00,113.00,2.00],[40951.00,-8663.00,2.00],[49051.00,-12825.00,1.00],[55463.00,-3488.00,2.00],[60413.00,7200.00,2.00],[51638.00,10238.00,1.00]],\"w\":0},{\"h\":0,\"points\":[[37913.00,9675.00,8.00],[34201.00,113.00,2.00],[28463.00,-7763.00,2.00],[36451.00,-12150.00,1.00],[42751.00,-3488.00,2.00],[46913.00,7088.00,2.00],[37913.00,9675.00,1.00]],\"w\":0},{\"h\":0,\"points\":[[-900.00,13725.00,8.00],[4501.00,2363.00,2.00],[8326.00,-10238.00,2.00],[17438.00,-8100.00,1.00],[16988.00,-6525.00,1.00],[24638.00,-9900.00,1.00],[30151.00,-675.00,2.00],[33638.00,10013.00,2.00],[24526.00,12263.00,1.00],[21376.00,2588.00,2.00],[16651.00,-5513.00,2.00],[12938.00,6188.00,2.00],[7876.00,16763.00,2.00],[-900.00,13725.00,1.00]],\"w\":0},{\"h\":0,\"points\":[[58276.00,-22613.00,8.00],[57826.00,-18788.00,2.00],[58276.00,-14850.00,2.00],[49838.00,-15525.00,2.00],[41288.00,-15525.00,2.00],[8326.00,-15525.00,1.00],[5176.00,-15525.00,2.00],[2026.00,-14850.00,2.00],[2363.00,-18788.00,2.00],[2026.00,-22613.00,2.00],[5176.00,-21938.00,2.00],[8326.00,-21938.00,2.00],[27563.00,-21938.00,1.00],[27563.00,-30938.00,1.00],[13051.00,-30938.00,1.00],[9901.00,-30938.00,2.00],[6751.00,-30263.00,2.00],[7088.00,-34088.00,2.00],[6751.00,-37913.00,2.00],[9901.00,-37350.00,2.00],[13051.00,-37350.00,2.00],[27563.00,-37350.00,1.00],[27563.00,-44775.00,1.00],[7201.00,-44775.00,1.00],[7201.00,-85613.00,1.00],[55351.00,-85613.00,1.00],[55126.00,-44775.00,1.00],[36113.00,-44775.00,1.00],[36113.00,-37350.00,1.00],[38701.00,-37350.00,1.00],[45563.00,-37350.00,2.00],[52538.00,-37913.00,2.00],[52088.00,-34088.00,2.00],[52538.00,-30263.00,2.00],[44438.00,-30938.00,2.00],[36113.00,-30938.00,2.00],[36113.00,-21938.00,1.00],[41288.00,-21938.00,1.00],[49838.00,-21938.00,2.00],[58276.00,-22613.00,2.00]],\"w\":0},{\"h\":0,\"points\":[[15863.00,-51188.00,8.00],[27563.00,-51188.00,1.00],[27563.00,-79200.00,1.00],[15863.00,-79200.00,1.00],[15863.00,-73013.00,1.00],[20588.00,-74250.00,1.00],[26776.00,-56700.00,1.00],[17776.00,-54225.00,1.00],[15863.00,-59738.00,1.00],[15863.00,-51188.00,1.00]],\"w\":0},{\"h\":0,\"points\":[[36113.00,-64800.00,8.00],[38363.00,-69638.00,2.00],[39713.00,-75375.00,2.00],[43201.00,-73350.00,2.00],[46688.00,-72000.00,2.00],[46688.00,-79200.00,1.00],[36113.00,-79200.00,1.00],[36113.00,-64800.00,1.00]],\"w\":0},{\"h\":0,\"points\":[[36113.00,-51188.00,8.00],[46576.00,-51188.00,1.00],[46576.00,-67275.00,1.00],[38813.00,-52538.00,1.00],[37463.00,-53438.00,2.00],[36113.00,-54225.00,2.00],[36113.00,-51188.00,1.00]],\"w\":0}],\"w\":115313.00,\"x\":0.00,\"y\":-94080.00},{\"bx\":0.00,\"by\":0.00,\"h\":115110.00,\"paths\":[{\"h\":0,\"points\":[[68513.00,-92025.00,8.00],[75151.00,-91238.00,2.00],[81788.00,-92025.00,2.00],[81788.00,-69300.00,2.00],[79201.00,-53550.00,2.00],[81788.00,-35775.00,2.00],[90900.00,-20306.00,2.00],[100013.00,-4838.00,2.00],[115538.00,10238.00,2.00],[108451.00,11138.00,2.00],[103726.00,16313.00,2.00],[83363.00,-4050.00,2.00],[74588.00,-33750.00,2.00],[62551.00,4275.00,2.00],[31388.00,19238.00,2.00],[29138.00,13500.00,2.00],[24976.00,9000.00,2.00],[52313.00,-3150.00,2.00],[63113.00,-31725.00,2.00],[68626.00,-48938.00,2.00],[68513.00,-71325.00,2.00],[68513.00,-92025.00,1.00]],\"w\":0},{\"h\":0,\"points\":[[-112.00,-47025.00,8.00],[338.00,-52650.00,2.00],[-112.00,-58163.00,2.00],[4051.00,-57263.00,2.00],[8326.00,-57263.00,2.00],[24976.00,-57263.00,1.00],[24976.00,-5625.00,1.00],[35888.00,-19800.00,1.00],[39488.00,-26888.00,1.00],[45788.00,-18563.00,1.00],[41626.00,-14513.00,1.00],[21038.00,14513.00,1.00],[14401.00,8325.00,1.00],[15976.00,5400.00,2.00],[15976.00,1913.00,2.00],[15976.00,-48038.00,1.00],[7313.00,-48375.00,2.00],[-112.00,-47025.00,2.00]],\"w\":0},{\"h\":0,\"points\":[[22726.00,-71325.00,8.00],[16651.00,-81450.00,2.00],[8438.00,-89325.00,2.00],[15413.00,-95850.00,1.00],[24976.00,-86738.00,2.00],[31276.00,-75938.00,2.00],[22726.00,-71325.00,1.00]],\"w\":0}],\"w\":115538.00,\"x\":0.00,\"y\":-95872.00},{\"bx\":0.00,\"by\":0.00,\"h\":115703.00,\"paths\":[{\"h\":0,\"points\":[[112725.00,-71775.00,8.00],[112275.00,-66825.00,2.00],[112725.00,-61875.00,2.00],[99450.00,-62438.00,2.00],[86063.00,-62663.00,2.00],[84600.00,-48825.00,2.00],[79144.00,-35831.00,2.00],[73688.00,-22838.00,2.00],[64913.00,-12150.00,2.00],[74475.00,-3938.00,2.00],[86287.00,956.00,2.00],[98100.00,5850.00,2.00],[110700.00,6863.00,2.00],[105863.00,11700.00,2.00],[105188.00,18450.00,2.00],[77513.00,15075.00,2.00],[57600.00,-4163.00,2.00],[46800.00,6300.00,2.00],[33187.00,12544.00,2.00],[19575.00,18788.00,2.00],[3938.00,19575.00,2.00],[4050.00,13725.00,2.00],[2025.00,8100.00,2.00],[15750.00,7763.00,2.00],[28350.00,2644.00,2.00],[40950.00,-2475.00,2.00],[50850.00,-11475.00,2.00],[42188.00,-22050.00,2.00],[37125.00,-35156.00,2.00],[32063.00,-48263.00,2.00],[31163.00,-62663.00,2.00],[10463.00,-62663.00,1.00],[6075.00,-62663.00,2.00],[1913.00,-61875.00,2.00],[2363.00,-66825.00,2.00],[1913.00,-71775.00,2.00],[6075.00,-70988.00,2.00],[10463.00,-70988.00,2.00],[57938.00,-70988.00,1.00],[50400.00,-81113.00,2.00],[41063.00,-90338.00,2.00],[49275.00,-96075.00,1.00],[59288.00,-86288.00,2.00],[67275.00,-75375.00,2.00],[58613.00,-70988.00,1.00],[79425.00,-70988.00,1.00],[96075.00,-70988.00,2.00],[112725.00,-71775.00,2.00]],\"w\":0},{\"h\":0,\"points\":[[57938.00,-18900.00,8.00],[73688.00,-38025.00,2.00],[73688.00,-62663.00,2.00],[39938.00,-62663.00,1.00],[40838.00,-37800.00,2.00],[57938.00,-18900.00,2.00]],\"w\":0}],\"w\":112725.00,\"x\":0.00,\"y\":-96128.00},{\"bx\":0.00,\"by\":0.00,\"h\":113067.00,\"paths\":[{\"h\":0,\"points\":[[112725.00,-30150.00,8.00],[112275.00,-25425.00,2.00],[112725.00,-20700.00,2.00],[95963.00,-21488.00,2.00],[79200.00,-21488.00,2.00],[59963.00,-21488.00,1.00],[59963.00,3825.00,1.00],[59963.00,10463.00,2.00],[56700.00,13500.00,2.00],[54113.00,16200.00,2.00],[50513.00,16537.00,2.00],[46913.00,16875.00,2.00],[45113.00,16763.00,2.00],[33863.00,16425.00,1.00],[34200.00,10913.00,2.00],[33075.00,5513.00,2.00],[38363.00,6075.00,2.00],[40725.00,6075.00,2.00],[43088.00,6075.00,2.00],[44381.00,6244.00,2.00],[45675.00,6413.00,2.00],[46631.00,6525.00,2.00],[47588.00,6638.00,2.00],[48488.00,6638.00,2.00],[50288.00,6525.00,2.00],[50288.00,4613.00,2.00],[50288.00,-21488.00,1.00],[9338.00,-21488.00,1.00],[5288.00,-21488.00,2.00],[1238.00,-20700.00,2.00],[1688.00,-25425.00,2.00],[1238.00,-30150.00,2.00],[5288.00,-29363.00,2.00],[9338.00,-29363.00,2.00],[50288.00,-29363.00,1.00],[50288.00,-37238.00,1.00],[70313.00,-52425.00,1.00],[29138.00,-52425.00,1.00],[25088.00,-52425.00,2.00],[21038.00,-51638.00,2.00],[21488.00,-56363.00,2.00],[21038.00,-61088.00,2.00],[25088.00,-60300.00,2.00],[29138.00,-60300.00,2.00],[87413.00,-60300.00,1.00],[88313.00,-51525.00,1.00],[84150.00,-50738.00,2.00],[80775.00,-48263.00,2.00],[59963.00,-32400.00,1.00],[59963.00,-29363.00,1.00],[79200.00,-29363.00,1.00],[95963.00,-29363.00,2.00],[112725.00,-30150.00,2.00]],\"w\":0},{\"h\":0,\"points\":[[13725.00,-59963.00,8.00],[4163.00,-59963.00,1.00],[4163.00,-81450.00,1.00],[51525.00,-81450.00,1.00],[41738.00,-90225.00,1.00],[49500.00,-96188.00,1.00],[61875.00,-85163.00,1.00],[57038.00,-81450.00,1.00],[105525.00,-81450.00,1.00],[105525.00,-59963.00,1.00],[95963.00,-59963.00,1.00],[95963.00,-73575.00,1.00],[13725.00,-73575.00,1.00],[13725.00,-59963.00,1.00]],\"w\":0}],\"w\":112725.00,\"x\":0.00,\"y\":-96192.00}]}]},\"pos\":{\"ct\":2,\"h\":10,\"w\":200,\"x\":0,\"y\":0},\"style\":{\"bi\":0,\"color\":{\"b\":34,\"ct\":202,\"g\":29,\"r\":182},\"cs\":0.00,\"fn\":\"文泉驿等宽正黑\",\"force\":0,\"fs\":36.00,\"ls\":10.00,\"max\":100,\"min\":1,\"po\":1,\"td\":0,\"vpo\":2},\"te\":\"默认文字\"}"
        };
        return callback(null, obj);
    };

    /**
     * 获取 APP 的控制字段信息
     *
     * @author 王俊
     * @date 2017-12-11
     *
     * @param device    设备型号标识
     * @param callback
     *          err: 错误
     *          data: 控制字段信息
     */
    sundryUtil.getAppControlInfo = function (device, callback) {
        var obj = {
            "tel" : '027-87659960',             // 客服电话
            "enableAppraise": 0,                // 是否允许评价(个人中心去评分是否显示), 第一版暂不显示
            "enableForm" : 1,                   // 是否支持表单功能
            "videoShareTitle" : "我用一键秀制作了炫酷宣传片，求围观",   // 视频分享标题
            "videoShareMsg" : "快速生成企业宣传片，海量模版免费用",     // 视频分享内容
            "desigShareTitle" : "我用一键秀制作了炫酷美图，求围观",     // 设计分享标题
            "desigShareMsg" : "快速生成企业宣传片，海量模版免费用",     // 设计分别内容
            "customVideoShareTitle" : "站住~我为你做了个宣传短视频，赶紧来看~",     // 自由创建默认分享标题
            "customVideoShareMsg" : "快速生成企业营销短视频  就在一键秀APP~",     // 自由创建默认分享内容
            "imgMaxSize" : 5000000,                                // 图片上传的资源最大值
            "imgNodeSizeMultiple" : 1.0,
            "privacyHtml" : "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"><meta charset=\"UTF-8\"><meta content=\"width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no\" name=\"viewport\"><style type=\"text/css\">body,html{width:100%;height:100%}body,html,div,p,h3,ul,li,a{padding:0;margin:0}ul{width:100%}div{font-size:.26rem;color:#333;padding:.1rem;width:100%;overflow:hidden;box-sizing:border-box}h3{margin-top:.3rem;margin-bottom:.3rem}p{text-indent:.38rem}@media (max-width:1442px){html{font-size:225px}}@media (max-width:1282px){html{font-size:200px}}@media (max-width:1026px){html{font-size:160px}}@media (max-width:962px){html{font-size:150px}}@media (max-width:952px){html{font-size:148.44px}}@media (max-width:902px){html{font-size:140.63px}}@media (max-width:802px){html{font-size:125px}}@media (max-width:775px){html{font-size:120.78px}}@media (max-width:770px){html{font-size:120px}}@media (max-width:738px){html{font-size:115px}}@media (max-width:734px){html{font-size:114.38px}}@media (max-width:733px){html{font-size:114.22px}}@media (max-width:669px){html{font-size:104.22px}}@media (max-width:642px){html{font-size:100px}}@media (max-width:602px){html{font-size:93.75px}}@media (max-width:570px){html{font-size:88.75px}}@media (max-width:535px){html{font-size:83.28px}}@media (max-width:437px){html{font-size:67.97px}}@media (max-width:416px){html{font-size:64.69px}}@media (max-width:413px){html{font-size:64.22px}}@media (max-width:386px){html{font-size:60px}}@media (max-width:377px){html{font-size:58.59px}}@media (max-width:362px){html{font-size:56.25px}}@media (max-width:322px){html{font-size:50px}}</style></head><body><div><p>感谢您使用一键秀！为了让您更加放心的使用一键秀及服务，下文将向您介绍一键秀对部分用户数据的使用情况。请您在使用前查看完整的 <a href=\"http://test.itbour.com:3011/html/userAgreement.html\">用户协议</a>，以便您能够更好地行使个人权利及保护个人信息。</p><h3>个人信息</h3>在为您提供以下（但不仅限于）以下功能：<ul><li>1.制作作品和生成草稿</li><li>2.收藏作品和下载个人作品</li><li>3.多平台，多终端作品同步</li></ul><p>需要填写手机号登录或第三方登录，一键秀需要依据您提供的信息和授权进行服务。请您在填写或授权前充分考虑并审慎决策。 为了您的权益，如果您对隐私权政策及服务条款的内容有任何疑问，请您通过客服渠道进行询问，一键秀将为您解释。一旦您开始使用一键秀产品或服务，即表示您已经理解并同意前述协议。该协议即构成对您具有约束力的法律文件。</p></div></body></html>",
            "alwaysShowPrivacyHtml" : 1,
            // app 1.7 新增挑战活动相关配置
            "hiddenHomeActivityCarousel" : 0,                           // 是否隐藏首页轮播, 0 不隐藏, 1 隐藏
            "hiddenActivityTab" : 0,                                    // 是否隐藏活动 tab 页, 0 不隐藏, 1 隐藏
            "hiddenMyActivity" : 0,                                     // 是否隐藏个人中心我的活动, 0 不隐藏, 1 隐藏
            "hiddenMyReward" : 0 ,                                      // 是否隐藏个人中心我的收益, 0 不隐藏, 1 隐藏
            "hiddenCustEntrance": 0,                                    // 是否隐藏自由创建入口, 0 不隐藏, 1 隐藏
            "androidCompressBitrate": 3000,                             // 安卓视频压缩比特率控制值 3000K
        };

        // android 配置
        if(Number(device) === 610) {
            obj.supportVideoEncode = ['video/avc'];
            obj.qGroupUrl = 'mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D' + 'ztNaNa1m5vu9aRL2jOlat5f3KILwRRGK';
        }
        // iOS 配置
        if(Number(device) === 620) {
            obj.supportVideoEncode = ['vide/avc1'];
            obj.qGroupUrl = 'mqqapi://card/show_pslcard?src_type=internal&version=1&uin=601104041&key=1e918f83808e2134829b4cf0a4c90e752ec6fe3539bde9727bc0421430375fcd&card_type=group&source=external';
        }

        return callback(null, obj);
    };

    /**
     * 获取 APP 长度控制字段信息
     *
     * @author 王俊
     * @date 2017-12-11
     *
     * @param callback
     *          err: 错误信息
     *          data: 控制字段信息
     */
    sundryUtil.getAppLenControlInfo = function (callback) {
        var obj = {
            "nickNameMaxLen": 10,           // 昵称最大长度
            "signMaxLen" : 15,              // 签名最大长度
            "WTTextMaxLen" : 100,           // 微调文字最大长度
            "tableTextMaxLen": 10,          // 表格内文字最大长度
            "tableMaxRow" : 15,             // 表格最大行
            "tableMaxCol" : 6,              // 表格最大列
            "FTMaxImageCnt" : 10,           // 微调可编辑图片对象最大个数
            "FTMaxTextCnt" : 20,            // 微调可编辑文字对象最大个数
            "productNameMaxLen" : 12        // 用户作品名称最大字数
        };
        return callback(null, obj);
    };

    /***
     * 获取 OSS 上传文件签名
     *
     * @author 王俊
     * @date 2017-11-15
     *
     * @param strToSign 待签名的字符串
     * @param callback 回调
     *          error: 签名失败
     *          data: {
     *              accessKeyId: 签名 key,
     *              signature: 签名
     *          }
     */
    sundryUtil.getOssSign_v1_0 = function (strToSign, callback) {
        var deadLine = Date.parse(new Date()) / 1000 + 3600;// 1小时以后
        var policyText = {
            "expiration": deadLine, // 设置该Policy的失效时间
            "conditions": [
                ["content-length-range", 0, 104857600] // 100M
            ]
        };
        //var strToSign = JSON.stringify(policyText);
        var myOSS = OSSMgr.get(CONFIG.BUCKET_ITBOUR_USER);
        if (!myOSS) {
            return callback('签名失败', null);
        }
        var sign = myOSS.signature(strToSign);
        var retData = {
            accessKeyId: myOSS.options.accessKeyId,
            signature: sign
        };
        return callback(null, retData);
    };


    /***
     * 获取 app 开屏广告信息
     *
     * @author 李强
     * @date 2017-11-16
     * @param screenW 需要的宽
     * @param screenH 需要的高
     * @param appVer  版本号
     * @param callback 回调
     *              error:
     *              data: {}
     */
    sundryUtil.getAppAdInfo_v1_0 = function(screenW, screenH,appVer, callback){
        (new YjxNotificationModel()).getAppAdInfo_v1_0(screenW, screenH, appVer, function(error, info){
            if(error || !info) {
                return callback(error || '暂无开屏广告信息', null);
            }
            // 如果类型为1, 广告图显示, 却没有图片链接, 返回失败
            if(info.kind== 1 && (!info.displayUrl || info.displayUrl.length <= 0)) {
                return callback('暂无开屏广告信息', null);
            }

            // 统一获取图片尺寸
            sundryUtil.getOssImgSize(info.displayUrl, function(error, data){
                if(error) {
                    return callback(error, null);
                }
                info.imgW = Math.floor(data.w);
                info.imgH = Math.floor(data.h);

                var ossProcessPrefix = '?x-oss-process=image';
                // 图片的宽高比要是超出了屏幕的宽高比, 则调整图片比例至屏幕宽高比
                var imgR = info.imgW / info.imgH;
                var deviceR = screenW /screenH;
                if (deviceR > imgR) {
                    var h = Math.floor(info.imgW / deviceR);
                    info.displayUrl += info.displayUrl.indexOf(ossProcessPrefix) == -1 ? ossProcessPrefix : '';
                    info.displayUrl+='/crop,x_0,y_0,w_'+info.imgW+',h_'+h;
                    info.imgH = h;
                }
                // 屏幕宽度小于图片宽度则有缩放余地, 可将图片缩放至屏幕宽, 若屏幕宽度比图片还宽, 为了防止图片过大, 则不进行放大操作
                if (screenW < data.w) {
                    info.displayUrl += info.displayUrl.indexOf(ossProcessPrefix) == -1 ? ossProcessPrefix : '';
                    info.displayUrl+='/resize,w_'+screenW;
                    var w = Math.floor(screenW);
                    var h = Math.floor(w * info.imgH/ info.imgW);
                    info.imgW = w;
                    info.imgH = h;
                }
                // 经过比例调整, 宽度缩放后,
                if (screenH < info.imgH) {
                    info.displayUrl += info.displayUrl.indexOf(ossProcessPrefix) == -1 ? ossProcessPrefix : '';
                    info.displayUrl+='/crop,x_0,y_0,w_'+info.imgW+',h_'+Math.floor(screenH);
                    info.imgH = Math.floor(screenH);
                }

                //暂时写死
                info.displayType = 1;
                return callback(null, info);
            });
        });
    };

    /***
     * 获取图片尺寸：仅仅适用于阿里云oss
     *
     * @author 李强
     * @date 2017-11-16
     * @param imgUrl: oss图片地址
     * @param callback，回调,参数如下：
     *        error:错误
     *        data:对象，结构如下：w:width
     *                           h:height
     */
    sundryUtil.getOssImgSize = function(imgUrl, callback){
        if(!imgUrl){
            return callback(null,null);
        }

        var url = imgUrl+'?x-oss-process=image/auto-orient,1/info'; // 自动旋转到正向
        superagent.get(url)
            .end(function(err, res){
                    if(err){
                        return callback(err, null);
                    }
                    var retJson = JSON.parse((res.text||'{}'));
                    if(retJson && retJson.ImageHeight && retJson.ImageWidth){
                        var ret = {};
                        if(retJson.Orientation && (retJson.Orientation.value==6 || retJson.Orientation.value==8) ){
                            ret.w = retJson.ImageHeight.value*1;
                            ret.h = retJson.ImageWidth.value*1;
                        }else{
                            ret.h = retJson.ImageHeight.value*1;
                            ret.w = retJson.ImageWidth.value*1;
                        }
                        return callback(null, ret);
                    }
                    return callback(null, null);
                }
            );
    };

    /**
     * 上传 APP 错误日志接口
     *
     * @author 毛凯
     * @date 2017-11-17
     *
     * @param device
     *          6字段为 一键秀 相关标记
     *          600 一键秀网页端
     *          610 一键秀 android 端
     *          620 一键秀 iOS 端
     *          630 一键秀 嵌入网页端
     *          640 一键秀微信端
     *          650 一键秀小程序端
     * @param userId 用户唯一标识
     * @param deviceInfo 自动搜集信息
     * @param errorLog  错误日志
     * @param callback 回调
     *              err 错误信息
     * */
    sundryUtil.uploadAppErrLog_v1_0 = function(device,userId,deviceInfo,errorLog,callback){
        var entity =  new YjxFeedBackModel({
            fb_type:20,
            device: device,
            user_id: userId,
            device_info_sys: deviceInfo,
            advice:errorLog
        });
        entity.saveToDB(function(err){
            if(err){
                console.log("sundryUtil.js [saveToDB] err" + err);
            }
            return callback(err);
        });
    };

    /***
     * 获取 APP 最新版本下载地址
     *
     * @author 毛凯
     * @date 2017-11-20
     *
     *                是否必须
     * @param device	是       610  6 字段为 一键秀 相关标记
     *                        600 一键秀网页端
     *                        610 一键秀 android 端
     *                        620 一键秀 iOS 端
     *                        630 一键秀 嵌入网页端
     *                        640 一键秀微信端
     *                        650 一键秀小程序端
     * @param callback 回调
     *                  err 错误信息
     *                  result "data" : {
     *	                        "lastVersion" : "5.7.0",
     *	                        "apkUrl" : "http://oss-itbour-yi-jian-sheng-cheng/5.7.0/yijianshengcheng.apk",
     *	                        "upgradeUrl" : "http://www.itbour.com/app/upgrade.html"
     *                    }
     * */
    sundryUtil.getLastVersion_v1_0 = function(device,callback){
        (new YjxProductVerModel()).getYjxProductVer(device,function(err,result){
                return callback(err,result);
        });
    };

    /**
     * 从 redis 中搜索统一商品信息
     *
     * @author 王俊
     * @date 2017-11-27
     *
     * @param showTypes     显示分类数组
     * @param keywords      搜索关键词数组(去特殊字符标点符号等)
     * @param setIds        模板组数组
     * @param orderBy       排序方式, 暂定: 1. 按时间倒序, 2. 按使用次数排序
     * @param pageNum       请求页码, 从0开始
     * @param pageSize      请求页容量
     * @param withTotalPage 是否获取总页数
     * @param userId        用户唯一标识
     * @param tmplTypes     模板分类数组
     * @param durations     视频时长 1,0s-10s 2,11s-30s 3,31s-60s  4,61s-90s
     * @param callback      回调
     *          error: 查询失败
     *          data : {
     *              list: 查寻的结果列表
     *              totalPage : 总页数
     *          }
     */
    sundryUtil.searchUniItemsFromRedis = function (showTypes, keywords, setIds,orderBy, pageNum, pageSize, withTotalPage,userId,tmplTypes,durations,sizeIds,callback) {

        // 分词操作
        var kwds = sundryUtil.doSegmentOfText(keywords);
        var param={
            showTypes : showTypes || [],
            keyword : kwds || [],
            setIds : setIds || [],
            orderBy : orderBy || 4,
            pageNum : pageNum,
            pageSize : pageSize,
            withTotalPage : withTotalPage || 0,
            tmplTypes : tmplTypes || [0,10],
            durations : durations || [1,2,3],
            sizeIds : sizeIds || [90,95]
        };
        //调用lua搜索
        luaUtil.searchUniItemsFromRedis(param, callback);



//        var param={
//            showTypes : showTypes,
//            keyword : keywords,
//            setIds : setIds,
//            orderBy : orderBy,
//            pageNum : pageNum,
//            pageSize : pageSize,
//            withTotalPage : withTotalPage,
//            tmplTypes : tmplTypes,
//            durations : durations
//        };
//        javaSearchProjectUtil.searchUniItemsFromJavaRedis(param, function (error, List) {
//            if(error){
//                console.log("luaUtil.js [searchUniItemsFromJavaRedis] err"+error);
//                return callback("没有获取到数据",{});
//            }
//            if(!List){
//                return callback("没有获取到数据",{});
//            }
//            //if(List.data.list.length < 0){
//            //    return callback("没有搜索到数据",{});
//            //}
//            return callback(null,List.data);
//        });
    };


    /**
     * 分词, 在 luaUtil 中也有一份, 重复是为了避免 util 间相互引用
     *
     * @author 王俊
     * @date 2017-11-27
     *
     * @param txt 待分词内容
     * @param min 可分词的最小长度, 默认2
     * @param max 可分词的最大程度, 默认6
     * @return 分词结果, 字符串数组
     */
    sundryUtil.doSegmentOfText = function(txt,min,max){
        if(!txt)    return null;
        // 只能2-6个字以内分词
        min = min || 1;
        max = max || 10;
        if(txt.length>max || txt.length<min){
            return [txt];
        }
        var segs = segment.doSegment(txt);
        var segWords=[];
        for(var i=segs.length-1 ; i>=0;i--){
            var one = segs[i];
            if(one.p !== POSTAG.D_W){//过滤掉标点符号
                // 过滤掉部分词语，例如：色
                var w = one.w.replace(/色/g,'');
                segWords.push(w);
            }
        }
        segWords.push(txt);
        return segWords;
    };

    /**
     * 获取 APP 的轮播图信息
     *
     * @author 王俊
     * @date 2018-01-05
     *
     * @param appVer      app 版本号, 如: "1.0.1"
     * @param callback    回调
     *          err: 错误
     *          data: {
     *                  w: 轮播图宽,
     *                  h: 轮播图高,
     *                  bannners: 轮播图列表
     *                }
     */
    sundryUtil.getAppBannerInfo_v1_1 = function(appVer, callback) {
        var entity = new YjxNotificationModel();
        entity.getAppBanner_v1_1(function (err, banners) {
            if(err || !banners || banners.length <=0) {
                return callback(err || '暂无轮播信息', null);
            }
            var data = {};
            data.w = 750;
            data.h = 300;
            data.banners = banners;
            return callback(err, data);
        });
    };

    /**
     * APP 启动激活
     *
     * @author 王俊
     * @date 2018-01-17
     *
     * @param appId         APP 唯一标识
     * @param idfa          设备广告标识
     * @param appVer        APP 版本号
     * @param deviceInfo    设备信息
     * @param callback      回调
     *          err:        激活失败
     */
    sundryUtil.appLaunchActivate = function(appId, idfa, appVer, deviceInfo, callback){
        var url = CONFIG.DEV_AD_SERVER_FULL_URL + '/asovip/activeIdfaDevice' + '?appid=' + appId + '&idfa='+idfa;
        console.log('appLaunchActivate: ' + url);
        superagent.get(url)
            .end(function (error, res) {
                if (error) {
                    return callback(error);
                }
                var resData = retUtil.safe_parser_JSON_string(res.text);
                if (!resData || Number(resData.code) !== 0) {
                    var errMsg = resData ? resData.msg : '激活失败';
                    return callback(errMsg);
                }
                return callback(null);
            });
    };



    /**
     * 获取视频各分类首页数据_WEB_1_0
     *
     * @author 毛凯
     * @date 2018-1-24
     *
     * @param pageSize      请求页容量
     * @param callback      回调
     *          error: 查询失败
     *          data : {
     *              videoTypes :[
     *                   {
     *                       id:9999,
     *                       name:"dddd",
     *                       setIds:[36],
     *                       list: [
     *                             {
     *                             查寻的结果列表
     *                           }
     *                       ]
     *                  },
     *              ]
     *          }
     */
    sundryUtil.getVideoFirstPageForWeb_v1_0 = function (pageSize, callback) {
        // 获取所有分类信息
        var ver = '1.0';
        sundryUtil.getAppShowTypesInfo(ver, function (err, showTypes) {
            if(err || !showTypes || showTypes.length <=0 ){
                console.log("sundry.js [getAppShowTypesInfo] err"+err);
                return callback(err,null);
            }
            // 提取视频分类
            var videoTypes = null;
            for(var i=0;i<showTypes.length;i++){
                if( Number(showTypes[i].id) === 2){
                    videoTypes = showTypes[i];  // 获取视频分类
                    break;
                }
            }
            if(!videoTypes || !videoTypes.children) return callback('暂未获取到视频分类信息',null);
            var tasks = [];
            // 获取视频分类列表信息
            videoTypes.children = videoTypes.children.slice(0,5);    // 网页端暂时限制首页获取前四个分类, 考虑到全部分类, 此处限制为五个
            for (var i=0; i<videoTypes.children.length; i++) {
                if(videoTypes.children[i].setIds.length >1) continue;   // 屏蔽全部分类
                var t = (function (videoType) {
                    return function (callback) {
                        var tmplTypes = [0,10]; // 同时获取免费和收费模板
                        var setIds = videoType.setIds;
                        var param={
                            showTypes : [],
                            keyword : [],
                            setIds : setIds,
                            orderBy : 4,
                            pageNum : 0,
                            pageSize : pageSize,
                            withTotalPage : 0,
                            tmplTypes : tmplTypes,
                            durations : [],
                            sizeIds:[90]
                        };

                        luaUtil.searchUniItemsFromRedis(param,function (error,data) {
                            if(error|| !data ){
                                console.log("luaUtil.js [searchUniItemsFromJavaRedis] err"+error);
                                return callback("没有获取到数据",null);
                            }
                            //模板数量小于页面要求值, 直接置空
                            videoType.list = data.list.length < pageSize ? [] : data.list;
                            return callback(error,videoType);
                        });
//                        javaSearchProjectUtil.searchUniItemsFromJavaRedis(param,function (error, response) {
//                            if(error|| !response || !response.data || !response.data.list ){
//                                console.log("luaUtil.js [searchUniItemsFromJavaRedis] err"+error);
//                                return callback("没有获取到数据",null);
//                            }
//                            // 模板数量小于页面要求值, 直接置空
//                            videoType.list = response.data.list.length < pageSize ? [] : response.data.list;
//                            return callback(error,videoType);
//                        });
                    };
                })(videoTypes.children[i]);
                if (t) {
                    tasks.push(t);
                }
            }
            async.parallel(tasks, function (error, results) {
                if(error) return callback(error, null);
                // 筛选有模板的分类返回
                var videoTypes = [];
                for (var i=0; i< results.length; i++) {
                    var type = results[i];
                    if(type && type.list.length > 0) {
                        videoTypes.push(type);
                    }
                }
                return callback(error, {videoTypes:videoTypes})
            });
        });

    };

    

    /**
     * 获取 APP 的轮播图信息
     *
     * @author 毛凯
     * @date 2018-2-1
     *
     * @param callback    回调
     *          err: 错误
     *          data: {
     *                  w: 轮播图宽,
     *                  h: 轮播图高,
     *                  bannners: 轮播图列表
     *                }
     */
    sundryUtil.getWebBannerInfo_v1_0 = function(callback) {
        var entity = new YjxNotificationModel();
        entity.getWebBanner_v1_1(function (err, banners) {
            if(err) {
                return callback(err || '暂无轮播信息', null);
            }
            var data = {};
            data.w = 1366;
            data.h = 400;
            data.banners = banners;
            return callback(err, data);
        });
    };

    /**
     * 获取 APP 基础信息中的视频子分类
     *
     * @author 王俊
     * @date 2018-03-01
     *
     * @param device        设备唯一标识
     * @param appVer        APP 版本号
     * @param callback      回调
     *          error
     */
    sundryUtil.getAppBaseVideoTypes_v1_3 = function (device, appVer, callback) {

        // 1. 获取视频分类
        // 1. 查询对应的中上层分类
        (new YjxShowTypeModel).getAppVideoSubTypeInfo(function (getTypeErr, types) {
            if (getTypeErr || !types || types.length === 0) {
                getTypeErr = getTypeErr ? getTypeErr : '暂无分类信息';
                return callback(getTypeErr, null);
            }
            // 将 types 数组转换为字典, 便于取数据
            var typeDic = {};
            for (var i=0;i<types.length;i++) {
                var tp = types[i];
                if (!typeDic[tp.st_id]) {
                    typeDic[tp.st_id] = {
                        st_id :tp.st_id,
                        parent : tp.parent,
                        name : tp.show_type_title,
                        desc : tp.show_type_desc,
                        children:[]
                    }
                }
                // 如果有组 id, 则为最小分类, 加入到指定分类的 children 中
                if (tp.set_id) {
                    var type = typeDic[tp.st_id];
                    type.children.push({
                        setIds : [tp.set_id],
                        name : tp.set_title,
                        desc : tp.set_desc,
                        children : [],
                        column : tp.column || 2     // 数据库暂时没有设置模板组显示列数的, 此处默认给2
                    });
                }

            }
            // 组织是数据结构
            var result = [];
            for (var key in typeDic) {
                var tp = typeDic[key];
                if(tp.parent) {
                    var type = typeDic[tp.st_id];
                    var parent = typeDic[tp.parent];
                    parent.children.push(type);
                } else {
                    result.push(tp);
                }
                tp.id = tp.st_id;
                tp.set_id = undefined;
                tp.parent = undefined;
            }

            // 手动添加全部分类, 暂时至支持一层
            for (var i=0; i< result.length; i++) {
                var type = result[i];

                // 如有下辖分类, 则存在全部分类, 默认加在第一位
                if (type.children && type.children.length >0) {
                    var allType = {
                        setIds : [],
                        name : '全部',
                        desc : '全部',
                        children : [],
                        column : 2 // 手动添加的全部分类, 此处默认给2
                    };
                    // 遍历子分类, 搜集 setIds
                    for (var j=0;j<type.children.length;j++) {
                        var subType = type.children[j];
                        if (subType.setIds) {
                            allType.setIds = allType.setIds.concat(subType.setIds);
                        }
                    }
                    if (allType.setIds.length) {
                        type.children.unshift(allType);
                    }
                }
            }
            return callback(null,result);
        })
    };

    /**
     * 获取 APP 视频所有子分类
     *
     * @author 王俊
     * @date 2018-03-01
     *
     * @param device        设备唯一标识
     * @param appVer        APP 版本号
     * @param callback      回调
     *          error
     *          list        分类数组
     *              [{
     *                  id:     模板组 id
     *                  icon:   模板组图标
     *                  name:   模板名称
     *                  setIds: 模板组 id 的数组格式, 前端请求使用
     *              }]
     */
    sundryUtil.getAppRelVideoTypes_v1_3 = function (device, appVer, callback) {
        //
        (new YjxShowTypeModel).getAppVideoSubTypeInfo(function (getTypeErr, types) {
            if (getTypeErr || !types || types.length <=0) {
                return callback(getTypeErr || '暂无分类信息');
            }
            var videoTypes = [];
            for (var i in  types) {
                var tmp = types[i];
                var t = {
                    id : tmp.set_id,
                    icon : tmp.icon,
                    name : tmp.set_title,
                    setIds : [tmp.set_id],
                    showCondition : 1, //列表页是否显示筛选条件,暂时写死
                    children : []
                };
                videoTypes.push(t);
            }
            return callback(getTypeErr, videoTypes);
        });
    };

    /**
     * 获取 APP 首页视频分类列表
     *
     * @author 王俊
     * @date 2018-03-01
     *
     * @param device        设备唯一标识
     * @param appVer        APP 版本号
     * @param callback      回调
     *          error
     */
    sundryUtil.getAppHomeVideoTypes_v1_3 = function (device, appVer, callback) {
        sundryUtil.getAppRelVideoTypes_v1_3(device, appVer, function (error, list) {
            if(error || !list || list.length <=0) {
                return callback(error || '暂无分类信息');
            }
            if(list.length <= 8) {
                return callback(error, list);
            }

            // 大于8 则取前8个, 暂不考虑全部分类
            var types = list.slice(0, 8);
            // var moreType = {
            //     id : -1,
            //     icon:list[7].icon,
            //     name : "全部",
            //     setIds:[]
            // };
            // for (var i=0; i<list.length; i++) {
            //     var setIds = list[i].setIds;
            //     if (!setIds || setIds.length <=0) continue;
            //     moreType.setIds = moreType.setIds.concat(setIds);
            // }
            // types.push(moreType);
            return callback(error, types);
        })
    };

    /**
     * 获取 APP 专题列表 (注意: 无数据情况, 也不报错)
     *
     * @author 王俊
     * @date 2018-03-01
     *
     * @param limit  限定专题个数
     * @param count  限定每个专题下的模板个数
     * @param tmplTypes 0 代表普通模板, 10 代表 vip 模板, 不传默认为 [0], 标记只获取普通模板
     * @param callback
     *            err:  错误
     *            specialTopics: 专题数组
     *              [{
     *                  id :            模板组 id
     *                  setIds:         模板组 id 的数组形式
     *                  name :          模板组名称
     *                  column : 2.5,   模板组显示列数暂时固定2.5列
     *                  direction : 1,  模板组显示方向 0 标记纵向排布, 1 标记横向排布, 暂定: 横向排布 1
     *                  showMore : 1,   模板组是否显示更多, 0 标记不显示更多, 1 标记显示更多
     *                  list: [],       模板组内模板数据列表
     *              }]
     */
    sundryUtil.getSpecialTopics_v1_3 = function (limit, count, tmplTypes, floatV,callback) {

        var tasks = [];
        // 1.获取模板组信息
        tasks.push(function (callback) {
            var entity = new YjxTmplSetModel();
            entity.getAllSpecialTopics(limit, function (error, results) {
                if (error) {
                    return callback(error);
                }
                var data = {};
                data.tmplSets = results;                //*** 记录专题
                return callback(error,data);
            });
        });

        // 2. 并发获取专题列表个数
        tasks.push(function (data, callback) {
            if (!data.tmplSets || data.tmplSets.length <=0) return callback(null, data);
            data.specialTopics = [];
            data.setIds = [];
            for (var i=0; i < data.tmplSets.length; i++) {
                var set = data.tmplSets[i];
                var sp = {
                    id : set.set_id,
                    setIds: [set.set_id],
                    name : set.title,
                    column : 2.5,   // 暂时固定2.5列
                    direction : 1,  // 0 标记纵向排布, 1 标记横向排布, 暂定: 横向排布
                    showMore : 1,   // 显示更多
                    showCondition : 0, //占时写死 列表页是否显示筛选条件
                    list: []
                };
                data.specialTopics.push(sp);             //*** 记录专题
                data.setIds.push(set.set_id);             //*** 记录专题 id, 便于请求各专题内模板列表
            }
            return callback(null,data);
        });

        // 3. 分别获取模板列表并补齐
        tasks.push(function (data, callback) {
            if (!data.tmplSets || data.tmplSets.length <=0) return callback(null, data);
            if (!data.setIds || data.setIds.length <=0) return callback(null, data);

            // 分别获取各专题列表内的模板
            var ts = [];
            for (var i=0; i<data.setIds.length; i++) {
                var t = (function (setId) {

                    return function (callback) {
                        var param={
                            showTypes : [],
                            keyword : [],
                            setIds : [setId],
                            orderBy : 4,
                            pageNum : 0,
                            pageSize : count,
                            withTotalPage : 0,
                            tmplTypes : tmplTypes,
                            durations : []
                        };
                        if(floatV >2.4){
                            param.sizeIds = [90,95];
                        }
                        luaUtil.searchUniItemsFromRedis(param,function (err,result) {
                            var list = [];
                            if (result && result.list && result.list) {
                                list = result.list;
                            }
                            return callback(err, list);
                        });
//                        javaSearchProjectUtil.searchUniItemsFromJavaRedis(param,function (error, data) {
//                            var list = [];
//                            if (data && data.data && data.data.list) {
//                                list = data.data.list;
//                            }
//                            return callback(error, list);
//                        });
                    }

                })(data.setIds[i]);
                ts.push(t);
            }
            async.parallel(ts, function (error, results) {
                 if(error) {
                     return callback(error, data);
                 }
                 for (var i=0; i< data.specialTopics.length; i++) {
                     var sp = data.specialTopics[i];
                     sp.list = results[i];
                     if (sp.list.length >0) {
                         sp.w = sp.list[0].w;
                         sp.h = sp.list[0].h;
                     }
                 }
                 return callback(error, data);
            });
        });

        async.waterfall(tasks, function (error, data) {
            if(error || !data) {
                return callback(error, null);
            }
            return callback(error, data.specialTopics || []);
        });
    };

    /**
     * 获取 APP 的轮播图信息 (没有轮播图时返回空数组)
     *
     * @author 王俊
     * @date 2018-03-01
     *
     * @param appVer      app 版本号, 如: "1.0.1"
     * @param callback    回调
     *          err: 错误
     *          data: {
     *                  w: 轮播图宽,
     *                  h: 轮播图高,
     *                  bannners: 轮播图列表
     *                }
     */
    sundryUtil.getAppBannerInfo_v1_3 = function(appVer, callback) {
        var entity = new YjxNotificationModel();
        entity.getAppBanner_v1_1(function (err, banners) {
            if(err) {
                return callback(err, null);
            }
            var data = {};
            data.w = 750;
            data.h = 440;
            data.banners = banners;
            return callback(err, data);
        });
    };
    /**
     * 获取 APP 首页信息
     *
     * @author 王俊
     * @date 2018-03-01
     *
     * @param device        设备标识
     * @param appVer        APP 版本号
     * @param callback      回调
     *          err:        失败原因
     *          data:        参考 http://yapi.yijianxiu.com:7000/project/11/interface/api/1208
     */
    sundryUtil.getAppHomePageInfo_v1_3 = function(device, appVer, actPageSize,callback) {

        var tasks = [];
        // 1. 获取 APP banner 信息
        tasks.push(function (callback) {
            sundryUtil.getAppBannerInfo_v1_3(appVer, function (error, data) {callback(error, data);});
        });
        // 2. 获取视频子分类数组
        tasks.push(function (callback) {
            sundryUtil.getAppHomeVideoTypes_v1_3(device, appVer, function (error, data) {callback(error, data);});
        });
        // 3. 获取专题列表
        tasks.push(function (callback) {
            var tmplTypes = [0,10];
            var floatV = parseFloat(appVer);
            if (floatV <= 1.3) {    // 老版本 app 只获取免费模板
                tmplTypes = [0];
            }
            sundryUtil.getSpecialTopics_v1_3(5, 12, tmplTypes,floatV,function (error, data) {callback(error, data);});
        });
        // 4. 获取活动列表
        tasks.push(function (callback) {
            var param = {
                states : [20],
                pageNum : 0,
                pageSize : actPageSize,
                withTotalPage : 0,
                flag : 1
            };
            sundryUtil.getActivityList_v1_3(param, function (error, data) {
                callback(error, data);
            });
        });
        async.parallel(tasks, function (error, results) {
            if(error) {
                return callback(error, null);
            }

            //####################### 专题特殊处理 begin #########################
            // 专题最后一个 纵向排布 2 列
            var specialTopics = results[2];

            // 异常保护, 移除非正常的专题数据
            for (var i=specialTopics.length-1; i>=0; i--) {
                var sp = specialTopics[i];
                if(!sp.list || sp.list.length <=0) {
                    specialTopics.splice(i,1);
                }
            }
            // 固定最后一个专题的属性
            if (specialTopics && specialTopics.length >0) {
                var sp = specialTopics[specialTopics.length-1];
                sp.column = 2;
                sp.direction = 0;
                sp.showMore = 0;
            }
            // 长度限制, 横向的专区长度不超过 5
            for (var i=specialTopics.length-1; i>=0; i--) {
                var sp = specialTopics[i];
                // 横向最多显示5个
                if (sp.direction === 1) {
                    sp.list = sp.list.slice(0, 5);
                }
            }
            //####################### 专题特殊处理 end #########################

            var data = {
                banner : results[0] || {},
                videoTypes : results[1] || [],
                specialTopics : results[2] || [],
                activitys : results[3] || [],
                // 视频入口
                videoEntrances: {
                    template: {
                        hidden: 0,    // 控制是否显示
                        url: 'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/08/16/095615151_R7p2RImgiuuGTsihi7ZR',
                        w: 690,
                        h: 300
                    },
                    custom: {
                        hidden: 0,    // 控制是否显示
                        url: 'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/08/16/095615528_emkciC0b1s0xUUn8JlsL',
                        w: 690,
                        h: 300
                    }
                }
            };
            return callback(error, data);
        });

    };


    /**
     * 获取 APP 1.3.0 版本的基础信息(分类,字体,颜色)
     *
     * @author 毛凯
     * @date   2018-3-1
     *
     * @param device 设置标识
     * @param appVer 版本标识
     *
     * @param callback 回调
     *          error: 错误
     *          data: 数据 参见接口: http://114.55.172.253:7000/project/11/interface/api/1202
     *
     * */
    sundryUtil.getAppBaseInfo_v1_3 = function (device,appVer, callback) {
        var  ver = parseFloat(appVer);
        async.series([
            function (callback) {
                sundryUtil.getAppBaseVideoTypes_v1_3(device,appVer, function (err, data) {return callback(err,data);});
            },
            function (callback) {
                sundryUtil.getAppFineTuneFontList_v1_0(function (error, fontlist) {return callback(error, fontlist);});
            },
            function (callback) {
                sundryUtil.getAppFineTuneColorList(function (error, colorList) {return callback(error, colorList);});
            },
            function (callback) {
                sundryUtil.getAppFineTuneTextConfig(function (error, config) {return callback(error, config);});
            },
            function (callback) {
                sundryUtil.getAppControlInfo(device, function (error, config) {return callback(error, config);});
            },
            function (callback) {
                sundryUtil.getAppLenControlInfo(function (error, config) {return callback(error, config);});
            },
            function (callback) {
                sundryUtil.getAppVideoConditions(function (error, config) {return callback(error, config);});
            }
        ], function (error, results) {
            if (error) {
                return callback(error, null);
            }
            var videoConditions = results[6];
            //版本大于1.5不需要tmplCondition字段
            if (ver > 1.5){
                delete results[6].tmplCondition;
                videoConditions = results[6];
            }
            var data = {
                types : results[0],
                fontList : results[1],
                colorList : results[2],
                textConfig : results[3],
                appControl : results[4],
                lengthControl : results[5],
                videoConditions : videoConditions
            };
            // data.appControl.enableAppraise = 1; // 1.3版本支持去评分
            return callback(null,data);
        });
    };

    /**
     * 获取视频筛选条件
     * @author 毛凯
     * @date   2018-3-28
     * @param callback 回调
     *          error: 错误
     *          data: 数据 参见接口: http://114.55.172.253:7000/project/11/interface/api/1202
     */
    sundryUtil.getAppVideoConditions = function(callback){
        //暂时写死
        var videoConditions = {};
        var videoConditionOption = [
            {
                "id" : 1,
                "name" : "全部时长",
                "values" : [1,2,3]
            },
            {
                "id" : 1,
                "name" : "0s-15s",
                "values" : [1]
            },
            {
                "id" : 2,
                "name" : "31s-60s",
                "values" : [2]
            },
            {
                "id" : 3,
                "name" : "61s-90s",
                "values" : [3]
            }
        ];
        var videoCondition = {
            id : 1,
            name : "时长:"  ,
            requestKey : "durations",
            options : videoConditionOption
        };

        var tmplConditionOption = [
            {
                "id" : 1,
                "name" : "全部模板",
                "values" : [0,10]
            },
            {
                "id" : 1,
                "name" : "免费模板",
                "values" : [0]
            },
            {
                "id" : 2,
                "name" : "尊享模板",
                "values" : [10]
            }
        ];
        var tmplCondition = {
            id : 2,
            name : "模板:"  ,
            requestKey : "tmplTypes",
            options : tmplConditionOption
        };

        videoConditions.sizeCondition = {
            id: 3,
            name: "尺寸:",
            requestKey: "sizeIds",     // 对应搜索接口, 模板列表接口请求的参数 key
            options : [
                {
                    id: 1,
                    name : "全部",
                    values : [],
                },
                {
                    id : 2,
                    name : "16:9",
                    values : [90],
                },
                {
                    id : 3,
                    name : "9:16",
                    values : [95],
                }
            ]
        };
        //获取行业信息
        sundryUtil.getIndustryCondition(function (err,result) {
            if (err){
                return callback(err, null);
            }
            videoConditions.durationCondition = videoCondition;
            videoConditions.tmplCondition = tmplCondition;
            if (!result || result.length <= 0){
                videoConditions.industryCondition = {};
                return callback(null,videoConditions);
            }
            videoConditions.industryCondition = result;
            return callback(null,videoConditions);
        });
    };

    /**
     * 获取行业信息
     *
     * @author 毛凯
     * @date 2018-7-23
     *
     * @param callback    回调
     *          err: 错误
     *          data: {
     *           "id": 2,
     *           "name": "行业",
     *           "requestKey": "industrySetIds",     // 对应搜索接口, 模板列表接口请求的参数 key
     *           "options" : [
     *               {
     *                  "id" : 1,
     *                   "name" : "全部",
     *                   "values" : [11,2,3],
     *               }
     *           }
     */
    sundryUtil.getIndustryCondition = function(callback) {
        var entity = new YjxTmplSetModel();
        entity.getIndustryCondition(function (err, result){
            if(err){
                return callback(err,null);
            }
            var options = [];
            var industryCondition = {
                id: 2,
                name: "行业:",
                requestKey: "industrySetIds",     // 对应搜索接口, 模板列表接口请求的参数 key
                options : options
            };
            if (!result || result.length <= 0){
                return callback(null,industryCondition);
            }
            var num = 1;
            var setIds = [];
            var allTmplSet = {
                "id" : num,
                "name" : "全部",
                "values" : setIds
            };
            for (var i = 0;i<result.length;i++){
                var industry = result[i];
//                setIds.push(industry.set_id);
                var variable = {
                    id : ++num,
                    name : industry.title,
                    values : [industry.set_id]
                };
                options.push(variable);
            }
            options.push(allTmplSet);
            //通过id进行组内排序
            options.sort(function(a, b){
                return a.id - b.id;
            });

            return callback(err,industryCondition);
        });
    };

    /**
     * 获取视频子分类列表_APP_1_3
     *
     * @author 毛凯
     * @date 2018-3-1
     *
     * @param device
     * @param appVer
     * @param callback    回调
     *          err: 错误
     *          data: {
     *           "id" : 56,
     *           "icon" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U126431/2017/06/21/171532874_rc9Gw3iKBYeeKJfbCLoL.jpg",
     *           "name" : "推荐",
     *           "children":[],
     *           "setIds" : [3]
     *           }
     */
    sundryUtil.getVideoAllSubtypes_v1_3 = function(device,appVer,callback) {
        sundryUtil.getAppRelVideoTypes_v1_3(device,appVer, function (err, data){
            if(err){
                return callback(err,null);
            }
            return callback(err,{videoTypes:data});
        });
    };

    /**
     * 获取用户作品当前对应的视频文件的关键帧数组
     *
     * @author 王俊
     * @date 2018-03-08
     *
     * @param device        设备唯一标识
     * @param userId        用户唯一标识
     * @param uniDoc        作品唯一标识()
     * @param callback      回调
     *          error: 错误
     *          keyFrameTimes: 关键帧对应时刻数组
     */
    sundryUtil.getUserDocKeyFrameTimes_v1_3 = function(device, userId,  uniDoc, callback){
        var entity = new YjxVideoUserDocModel();
        entity.getUniVideoDocRes(uniDoc, 0/*默认低质量*/, function (error, videoRes) {
            if(error || !videoRes || !videoRes.url) {
                return callback(error || '该作品不存在或尚未排版', null);
            }
            var url = videoRes.url; // 视频资源链接
            // 优先取缓存
            var uri = 'yjx/v1/util/sundryUtil/getUserDocKeyFrameTimes_v1_3';
            var para = {uniDoc : uniDoc, videoUrl : url};
            staticizeUtil.getCacheDataByRedis(uri, para, function (getCacheErr, content) {
                if (!getCacheErr && content && CONFIG.DEBUG !== 1) {
                    return callback(getCacheErr, content);
                }
                // 没有获取到缓存, 真正获取
                rpcFunc.getVideoKeyFrameTimes(url, function (rpcErr, times) {
                    if (!rpcErr && times) {
                        // 封面时间内关键帧移除
                        if (videoRes.cover_dur && Number(videoRes.cover_dur) > 0) {
                            var dur = videoRes.cover_dur;
                            for (var i=times.length-1; i>=0; i--) {
                                if(dur >= Number(times[i])) {
                                    times.splice(i,1);
                                }
                            }
                        }
                        times.sort();
                        staticizeUtil.recordDataByRedis(uri, para, times);
                    }
                    return callback(rpcErr, times);
                });
            });
        });
    };

    /**
     * 获取 APP 端 VIP 页面信息
     *
     * @author 毛凯
     * @date 2018-3-28
     * @param {Object} options 函数参数
     * @param {String} options.device 请求设备
     * @param {String} options.appVer APP 版本号
     * @param callback    回调
     *          err: 错误
     *          data: {
     *                    "appHomeVipUrl" : "",       // 长度大于0时, 且以 http 开头, 标记以此字段作为 url 访问 web 页面显示
     *                       "vipProtocolUrl" : "http://apphome.yijianxiu.com/vipProtocol.html", // vip 协议链接
     *                       "introduceInfo" : {
     *                           "vipGoods" : [
     *                               {
     *                                   // 商品介绍相关
     *                                   "itemId" : 30123,                                     // vip 商品 id
     *                                   "priceId" : 101,                                    // 商品 id
     *                                   "itemName" : "vip 年度会员礼包",                    // 商品名称
     *                                   "itemDesc" : "免费使用尊享模板,获赠 30000 秀米",    // 商品描述
     *                                   "recommend" : 1,                                    // 0 标记不推荐, 1 标记显示推荐标记
     *                                   "adImg" : {
     *                                       "url" : "http://itbour-generate.itbour.com/video/U2/2017/12/05/013653510_mT2i0Ajhkw3p2XLyTmlw/thumb.jpg",
     *                                       "w" : 300,
     *                                       "h" : 200
     *                                   }
     *                               }
     *           }
     */
    sundryUtil.getAppVipInfo_v1_4 = function(options, callback) {
        var entity = new YjxUniItemsModel();
        entity.getUniItemVipInfo(function(deErr,deRes){
            if(deErr){
                return callback(deErr,null);
            }
            if(!deRes ||deRes.length<=0 ){
                return callback("没有获取到vip商品",null);
            }
            var vipYearImg ={
                url : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/03/28/151749917_cOhGOR4yvuJYt7bIxHeW.png",
                w : 450 ,
                h: 270
            };
            var vipQuarterImg ={
                url : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/03/28/151726404_Kv9FopR8racLdPztOqmd.png",
                w : 450,
                h:270
            };

            var vipGoods=[
                {
                    itemId : deRes[0].uni_item_id,
                    priceId : deRes[0].id,
                    itemName : deRes[0].itemName,
                    itemDesc : deRes[0].itemDesc,
                    recommend : 1,
                    adImg :vipYearImg
                },
                {
                    itemId : deRes[1].uni_item_id,
                    priceId : deRes[1].id,
                    itemName : deRes[1].itemName,
                    itemDesc : deRes[1].itemDesc,
                    recommend : 0,
                    adImg :vipQuarterImg
                }
            ];
            var bottomImg = {
                url :"http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/03/28/151739560_qPCgtcOfhSNLTVy6Ga8g.png",
                w : 449,
                h: 637
            };
            var introduce ={
                vipGoods : vipGoods,
                bottomImg : bottomImg
            };
           var data = {
               appHomeVipUrl : "",
               vipProtocolUrl : "/yjx/v1_0_0/user/vipAgreement",
               introduceInfo : introduce
           };
           // iOS  端
           if(options.device === 620) {
               introduce.vipBottomImg = {
                   url : 'http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U13/2018/04/10/104255836_GQ9GLH8DENdeix53klsI.jpg',
                   w : 750,
                   h : 1900
               };
           }
            return callback(null,data);
        });

    };

    /**
     * 获取视频链接对应的视频文件基础信息
     *
     * @author 王俊
     * @date 2018-04-04
     *
     * @param {Object} options 请求参数
     * @param {String} options.url 视频链接
     * @param callback
     */
    sundryUtil.getVideoBaseInfo_web_1_1 = function (options, callback) {
        rpcFunc.yjxGetVideoBaseInfo(options, callback);
    };

    /**
     * 获取活动列表
     * @param param    参数列表
     * @param {Array}  param.states    活动状态数组10未开场、20已开场、30活动截止、40活动关闭、50活动取消 数组的json字符串
     * @param {Number} param.pageNum   页码
     * @param {Number} param.pageSize  页容量
     * @param {Number} [param.userId]  用户id
     * @param {Number} [param.filterUser] 是否根据用户过滤活动列表, 0 不过滤, 1 过滤, 如使用该字段必须传递 userId
     * @param {Number} [param.checkReward] 是否检测用户在活动中的获奖状况,0 不过滤, 1 过滤,  如使用该字段必须传递 userId
     * @param {Number} param.withTotalPage 是否需要返回总页数  0不需要  1需要
     * @param callback
     */

    sundryUtil.getActivityList_v1_3 = function (param,callback) {
        activityUtil.getActivityList_v1_7(param,function (err,result) {
            if(err){
                return callback(err, null);
            }
            for (var i = 0;i<result.list.length;i++){
                var act = result.list[i];
                act.contentUrl = CONFIG.APP_HOME_SERVER_FULL_URL+"/activityDetail/"+act.id;
            }

            var data = {
                diplayType : 1,       // 展示样式, 预留字段1 标记横向不自动轮播
                showMore : 1,         // 是否显示更多
                title : "挑战活动",   // 区块标题
                h: 350,             // 区块图宽高比
                w: 710,
                list : result.list
            };
            return callback(err,data);
        });
    };



    /**
     * 获取自由创建配置信息_ APP_3_0 添加
     *
     *
     * @author 毛凯
     * @date 2018-07-04
     *
     * @param callback
     */

    sundryUtil.getCustomVideoConfigure_app_v3_0 = function (callback) {
        async.series([
            function (callback) {
                sundryUtil.getVideoFiltersInfo(function (err, data) {return callback(err,data);});
            },
            function (callback) {
                sundryUtil.getVideoTransitionsInfo(function (error,TransitionsInfo) {return callback(error, TransitionsInfo);});
            }
//            function (callback) {
//                sundryUtil.getVideoConfigurationsInfo(function (error, ConfigInfo) {return callback(error, ConfigInfo);});
//            },
        ], function (error, results) {
            if (error) {
                return callback(error, null);
            }

            var data = {
                filters : results[0],
                transitions : results[1],
                configurations : results[2],
            };
            return callback(null,data);
        });

    };

    /**
     * 获取滤镜信息
     * @param callback
     */
    sundryUtil.getVideoFiltersInfo = function(callback){

        /*
        *
        // 数据结构
        一
        Colormatrics 1602

        {
        "r":[0.2,0.4,0.4,0.5],
        "g":[0.2,0.4,0.4,0.5],
        "b":[0.2,0.4,0.4,0.5],
        "a":[0.2,0.4,0.4,0.5],
        "intensity":1.0
        }

        二
        Monocolor 1603

        {
        "color":[0.2,0.4,0.4],
        "intensity":1.0
        }

        三
        Sketch 1604
        无参数
        * */

        var filters = [
            //滤镜对象 1
            {
                "id" : 1,
                "name" : "原画",
                "icon" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/11/200503436_iQdRZ9vg1m5SNIugRa9I"
            },
            //滤镜对象 2
            {
                "id": 2,
                "name": "泛黄记忆",
                "icon": "https://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/06/153532199_VflEyKndNpvGd4NSXBR6",

                "ct": 1602,                 // 滤镜类型
                "params": {                // 滤镜参数, 不同滤镜参数不同
                    "r":[0.358,0.704,0.137,0.0],
                    "g":[0.299,0.587,0.114,0.0],
                    "b":[0.239,0.469,0.091,0.0],
                    "a":[0.0,0.0,0.0,1.0],
                    "intensity":1.0
                }
            },

            //滤镜对象 3
            {
                "id" : 3,
                "name" : "黑白",
                "icon" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/11/200501806_sTrB4eLH3weOq6VM426E",

                "ct": 1603,                 // 滤镜类型
                "params" : {                // 滤镜参数, 不同滤镜参数不同
                    "color":[0.5,0.5,0.5],
                    "intensity":1.0
                }
            },
            //滤镜对象 4
            {
                "id" : 4,
                "name" : "日系",
                "icon" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/11/200502816_tb78ddNPaPjL4Z2O7yLs",
                "ct": 1602,                 // 滤镜类型
                "params" : {                // 滤镜参数, 不同滤镜参数不同
                    "r":[0.835,0.0,0.0,0.0],
                    "g":[0.0,1.0,0.0,0.0],
                    "b":[0.0,0.0,1.0,0.0],
                    "a":[0.0,0.0,0.0,1.0],
                    "intensity":1.0
                }
            },
            //滤镜对象 5
            {
                "id" : 5,
                "name" : "暮光之城",
                "icon" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/11/200501899_HV77dqbYonPoJzCIbko9",
                "ct": 1602,                 // 滤镜类型
                "params" : {                // 滤镜参数, 不同滤镜参数不同
                    "r":[1.0,0.0,0.0,0.0],
                    "g":[0.0,0.894,0.0,0.0],
                    "b":[0.0,0.0,0.647,0.0],
                    "a":[0.0,0.0,0.0,1.0],
                    "intensity":1.0
                }
            },
            //滤镜对象 6
            {
                "id" : 6,
                "name" : "云中漫步",
                "icon" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/11/200503521_cXRlQ3gGJhhm7YeIQhtG",
                "ct": 1602,                 // 滤镜类型
                "params" : {                // 滤镜参数, 不同滤镜参数不同
                    "r":[0.741,0.0,0.0,0.0],
                    "g":[0.0,0.914,0.0,0.0],
                    "b":[0.0,0.0,0.792,0.0],
                    "a":[0.0,0.0,0.0,1.0],
                    "intensity":1.0
                }
            },
            //滤镜对象 7
            {
                "id" : 7,
                "name" : "青涩年华",
                "icon" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/11/200502401_fYLxoAwe9J5470HY5J3J",
                "ct": 1602,                 // 滤镜类型
                "params" : {                // 滤镜参数, 不同滤镜参数不同
                    "r":[0.518,0.0,0.0,0.0],
                    "g":[0.0,0.98,0.0,0.0],
                    "b":[0.0,0.0,0.824,0.0],
                    "a":[0.0,0.0,0.0,1.0],
                    "intensity":0.7
                }
            },
            //滤镜对象 8
            {
                "id" : 8,
                "name" : "素描",
                "icon" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/11/200503246_5BYn70DTvjtCI5UNNz9z",
                "ct": 1604,                 // 滤镜类型

            },
        ];
        return callback(null, filters);
    };

    /**
     * 获取转场的信息
     * @param callback
     * @returns {*}
     */
    sundryUtil.getVideoTransitionsInfo = function (callback) {
        var entity = new YjxCustAnimationModel();
        var totalTasks=[];
        //查询专场ids
        totalTasks.push(function (callback) {
            entity.findAnimationIds(function (err,result) {
               if (err){
                   return callback(err, null);
               }
                var data = {};
               data.animation = result || [];
               return callback(null,data);
            });
        });
        //通过转场ids获取转场核心数据
        totalTasks.push(function (data,callback) {
            if (!data || !data.animation){
                return callback("未获取到专场列表", null);
            }
            var transitions = [
                {
                    id: -1,
                    name: '无',
                    icon : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/13/154013687_i8Dk2ibX3jrNXCeeiqr6",
                }
            ];
            var tasks=[];
            for (var i=0; i<data.animation.length; i++) {
                var t = (function (animation) {
                    return function (ck) {
                        var anArr = JSON.parse(animation.anIds);
                        var anId = anArr[0];
                        entity.getAnimationInfo(anId,function (err,res) {
                            if(!res || !res[0]){
                                return ck(null,null);
                            }
                            var ani = JSON.parse(res[0].tmpl_set);
                            //解析转场核心数据
                            var aniVideo = {
                                id : anId,
                                name : animation.name || "",
                                icon : animation.icon || "",
                                ct  : ani[7].ct || 0 ,
                                dbId : anId,
                                intersect : ani[7].intersect || 0,
                                duration : ani[7].duration || 0,
                                layer : ani[7].layer || {}
                            };
                            transitions.push(aniVideo);
                            return ck(err,res);
                        });
                    };
                })(data.animation[i]);
                if (t) {
                    tasks.push(t);
                }
            }
            async.parallel(tasks, function (error, aniRes) {
                if(error) return callback(error, null);
                data.transitions = transitions;
                return callback(error, data)
            });
        });
        //流式执行
        async.waterfall(totalTasks, function (error, data) {
            if(error) return callback(error, null);
            return callback(error, data.transitions || []);
        });
    };

    /**
     * 获取自由创建的配置信息
     *
     * @deprecated app 3.0 直接写死, 不再返回
     *
     * @param callback
     * @returns {configurations}
     */
    sundryUtil.getVideoConfigurationsInfo = function (callback) {
        var configurations = [];
        //配置1
        var config1 = {
            "id" : 1,
            "name" : "9:16 竖长方形 适用于手机端抖音/微视等竖屏视频",
            "thumb" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/06/102000652_SjMi0kLA7NEUSrTAnFuW",   // 缩略图
            "w" : 9.0,                                            // 自由创建视频宽高
            "h" : 16.0,
            "maxDuration" : 60,                                     // 自由创建总时长最大最小值
            "minDuration" : 3,
            "sizeId" : 90
        };
        //配置2
        var config2 = {
            "id" : 2,
            "name" : "1:1 正方形 适用于电商类淘宝商品展示",
            "thumb" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/06/102339235_uZQ4tAITugswGnF8BpFm",   // 缩略图
            "w" : 1.0,                                            // 自由创建视频宽高
            "h" : 1.0,
            "maxDuration" : 60,                                     // 自由创建总时长最大最小值
            "minDuration" : 3,
            "sizeId" : 91
        };
        //配置3
        var config3 = {
            "id" : 3,
            "name" : "16:9 横长方形 适用于电脑端网站(京东)广告宣传",
            "thumb" : "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/image/U2/2018/07/06/102339420_17ie0FIifiV2yAvqedRl",   // 缩略图
            "w" : 16.0,                                            // 自由创建视频宽高
            "h" : 9.0,
            "maxDuration" : 60,                                     // 自由创建总时长最大最小值
            "minDuration" : 3,
            "sizeId" : 30
        };
        configurations.push(config1);
        configurations.push(config2);
        configurations.push(config3);
        return callback(null,configurations);
    };



    /**
     * 获取音乐库列表_APP_3_0 添加
     *
     * @author 毛凯
     * @date 2018-07-04
     *
     * @param pageNum    页码
     * @param pageSize  页容量
     * @param withTotalPage  是否需要分页
     * @param callback
     * @returns {}
     */
    sundryUtil.getAudioAssetsList_app_v3_0 = function (pageNum,pageSize,withTotalPage,callback) {
        var entity = new YjxUniItemsModel();
        entity.getMediaList(pageNum,pageSize,function (err,result) {
            if (err) {
                return callback(err, null);
            }
            if(!withTotalPage){
                return callback(null,{list:result||[]});
            }
            entity.getMediaListCnt(pageNum,pageSize,function(error,count){
                if (error){
                    return callback(error,null);
                }
                var totalPage = Math.floor((count-1)/pageSize)+1 || 0;
                return callback(null,{list:result||[],totalPage:totalPage,currentPage:pageNum});
            });
        });
    };



    /**
     * 获取弹窗广告
     *
     * @author 毛凯
     * @date 2018-07-23
     *
     * @param callback
     * @returns {}
     */
    sundryUtil.getActivityWindowInfo_app_v6_6 = function (callback) {
        var entity = new YjxNotificationModel();
        entity.getWindowInfo(function (err,result) {
           if (err){
               return callback(err, null);
           }
           var data = result[0]? result[0]:{};
           return callback(null,data);
        });
    };




    //----------------------------------------
    return sundryUtil;
})();
module.exports = sundryUtil;